package haust;

import java.nio.IntBuffer;
import static org.lwjgl.openal.AL10.*;

public class SoundSource {
	private IntBuffer sourceID;
	private Vec3 pos;
	private Vec3 vel;
	
	/**
	 * 
	 */
	public SoundSource()
	{
		sourceID = null;
	}
	
	/**
	 * 
	 * @param sourceID
	 * @param pos
	 * @param vel
	 */
	public SoundSource(IntBuffer sourceID, Vec3 pos, Vec3 vel) {
		this.setSourceID(sourceID);
		this.setPos(pos);
		this.setVel(vel);
		
		alSourcei(sourceID.get(0), AL_LOOPING, AL_TRUE);
	}

	/**
	 * 
	 * @return
	 */
	public int getSourceID() {
		if( sourceID != null )
			return sourceID.get(0);
		return -1;
	}

	/**
	 * 
	 * @param sourceID
	 */
	public void setSourceID(IntBuffer sourceID) {
		this.sourceID = sourceID;
	}

	/**
	 * 
	 * @return
	 */
	public Vec3 getPos() {
		return pos;
	}

	/**
	 * 
	 * @param pos
	 */
	public void setPos(Vec3 pos) {
		this.pos = pos;
	}

	/**
	 * 
	 * @return
	 */
	public Vec3 getVel() {
		return vel;
	}

	/**
	 * 
	 * @param vel
	 */
	public void setVel(Vec3 vel) {
		this.vel = vel;
	}
	
	/**
	 * Sends position and velocity values to OpenAL
	 */
	public void update()
	{
		if( sourceID == null )
			return;
		
		alSource( sourceID.get(0), AL_POSITION, pos.get() );
		alSource( sourceID.get(0), AL_VELOCITY, vel.get() );
	}
}
